package com.example.myweb.Repository.JpaRepository;

import com.example.myweb.Domain.Entity.Article;
import com.example.myweb.Domain.Entity.Collection;
import com.example.myweb.Domain.Entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface CollectionRepository extends JpaRepository<Collection, Long> {
    // 根据用户和文章ID删除收藏记录
    boolean existsByUserAndArticle_ArticleId(User user, Long articleId);

    Optional<Collection> findByUserAndArticle_ArticleId(User user, Long articleId);

    long deleteByUserAndArticle_ArticleId(User user, Long articleId);

    // 分页查询方法也需要修改
    Page<Collection> findByUser(User user, Pageable pageable);

}